<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    console.log(message) // undefined

    var message = "Global Message"

    function foo() {
      console.log(message) // undefined

      var message = "foo Message"

      console.log(message) // foo Message
    }

    foo()

  </script>

  <script>
    // 函数中没有message
    var message = "Global Message"

    function foo() {
      console.log(message) // Global Message
    }

    foo()

    var obj = {
      name: "obj",
      bar: function () {
        var message = 'bar message'
        foo()
      }
    }
    obj.bar() // Global Message

  </script>
</body>

</html>